package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.model.entity.AssociatesActivitesEntity;
import com.runen.infinitemovement.tool.GlideUtils;
import com.runen.infinitemovement.widget.imageview.RoundedCornersImage;

import java.util.List;

public class AssociatedActivitiesAdapter extends BaseQuickAdapter<AssociatesActivitesEntity.DataBean, BaseViewHolder> {
    private Context context;
    private boolean isCheck;

    public OnCheckClick getOnCheckClick() {
        return onCheckClick;
    }

    public void setOnCheckClick(OnCheckClick onCheckClick) {
        this.onCheckClick = onCheckClick;
    }

    private OnCheckClick onCheckClick;

    public AssociatedActivitiesAdapter(Context context) {
        super(R.layout.item_associated_activities);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, AssociatesActivitesEntity.DataBean item) {
        LinearLayout ll_set_associated = helper.getView(R.id.ll_set_associated);
        RoundedCornersImage rciBg = helper.getView(R.id.rci_bg);
        ImageView iv_check = helper.getView(R.id.iv_check);
        TextView tv_enter_num = helper.getView(R.id.tv_enter_num);
        TextView tv_activity_discrible = helper.getView(R.id.tv_activity_discrible);
        GlideUtils.loadImage(context, item.cover, rciBg);
        String str = "%s 人参与";
        tv_enter_num.setText(String.format(str, item.participantsCount));
        tv_activity_discrible.setText(item.name);
        ll_set_associated.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isCheck = !isCheck;
                if (isCheck) {
                    iv_check.setImageResource(R.mipmap.ico_selected_circle_red_v);
                } else {
                    iv_check.setImageResource(R.mipmap.ico_circel_red_stroke);
                }
                item.isCheck = isCheck;
                if (onCheckClick != null) {
                    onCheckClick.onCheckClick(item, isCheck);
                }
            }
        });
    }

    public interface OnCheckClick {
        void onCheckClick(AssociatesActivitesEntity.DataBean item, boolean isCheck);
    }
}
